import {
	defineStore
} from 'pinia'

import {
	ref
} from 'vue'

export const usePostStore = defineStore('post', () => {
		// 存储攻略数据对象
		const postData = ref({})

		// 将获取到的信息存入攻略数据
		const setPostData = (data) => {
			postData.value = {
				...postData.value,
				...data
			}
		}

		// 清空攻略数据
		const clearPostData = () => {
			postData.value = {}
		}

		return {
			postData,
			setPostData,
			clearPostData
		}
	},
	// 持久化
	{
		persist: {
			storage: {
				getItem(key) {
					return uni.getStorageSync(key)
				},
				setItem(key, value) {
					return uni.setStorageSync(key, value)
				}
			}
		}
	})